<!-- [COMPONENT] : 列操作按钮
使用示例：
1）基本使用
      <operation-column  :permi="permi"  @edit="handleUpdate"  @delete="handleDelete"/>
2）自定义按钮
      <operation-column  :permi="permi"  @edit="handleUpdate"  @delete="handleDelete">
        <template slot-scope="{ row }">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-setting"
            @click="handleSetting(row)"
          >设置
          </el-button>
        </template>
      </operation-column>
-->
<template>
  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
    <template slot-scope="scope">
      <!-- 修改按钮 -->
      <el-button
        v-if="showEdit"
        size="mini"
        type="text"
        icon="el-icon-edit"
        @click="handleEdit(scope.row)"
        v-hasPermi="[`${permi}:edit`]"
      >修改</el-button>

      <!-- 删除按钮 -->
      <el-button
        v-if="showDelete"
        size="mini"  class="delete"
        type="text"
        icon="el-icon-delete"
        @click="handleDelete(scope.row)"
        v-hasPermi="[`${permi}:remove`]"
      >删除</el-button>

      <!-- 自定义插槽 -->
      <slot :row="scope.row"></slot>
    </template>
  </el-table-column>
</template>

<script>
export default {
  name: 'OperationColumn',
  props: {
    // 权限前缀
    permi: {
      type: String,
      required: true
    },
    // 是否显示各个按钮
    showEdit: {
      type: Boolean,
      default: true
    },
    showDelete: {
      type: Boolean,
      default: true
    },
    showDetail: {
      type: Boolean,
      default: false
    },
    // 按钮配置
    buttonConfig: {
      type: Object,
      default: () => ({})
    }
  },
  methods: {
    handleEdit(row) {
      this.$emit('edit', row)
    },
    handleDelete(row) {
      this.$emit('delete', row)
    },
  }
}
</script>

<style lang="scss" scoped>
.delete {
  color: red;
}
</style>
